<?
require 'global.php';

$url='news';
$do=isset($_GET["do"])?clean($_GET["do"]):'view';// 备用字段
$id=0; if (isset($_GET["id"])) $id = clean($_GET["id"]);
$page=1; if(isset($_GET["page"]))if(is_numeric($_GET["page"]))$page=$_GET["page"];
$cateid=2; if(isset($_GET["cate"]))if(is_numeric($_GET["cate"]))$cateid=$_GET["cate"];

$tem = $news_category->get_rows(32,'','','seq_no');
$arr_cate=array();
foreach($tem as $val) $arr_cate[$val['id']]=$val;

if($id==0){
	$news->rows=10;
	if(!isset($arr_cate[$cateid])) { header('Location:404.html'); exit; }
	
	$where=array();
	$where[]=array('name'=>'language_id','val'=>$lang_id);
	$where[]=array('name'=>'category_id','val'=>$cateid);
	$order_by='id';
	$pages=$news->count_pages($where);
	$info=$news->get_page($page,$where,$order_by);
	// seo
	$cate_name=$arr_cate[$cateid]['name_'.$lang];
	$title=$cate_name.' - '.$config['SITE_TITLE_'.LANG];
	$kwd=$title;
	$dpn=$kwd;
}
else {
	$info=$news->get_row($id);
	if(is_null($info))  { header('Location:404.html'); exit; }

	$cateid=$info['category_id'];
	$cate_name=$arr_cate[$cateid]['name_'.$lang];
	$left=$news->get_left($id,'category_id',$cateid,$lang_id);
	$right=$news->get_right($id,'category_id',$cateid,$lang_id);
	// seo
	$title=$info['name'];
	$kwd=$dpn=$title;
	$news->click($id);
}
//标签
$where_t = array();
$where_t[] = array('name'=>'p_id', 'val'=>$id, 'opn'=>'=', 'and'=>'and');
$where_t[] = array('name'=>'tags_table', 'val'=>2, 'opn'=>'=', 'and'=>'and');
$tags_list_info = $tag_list->get_rows_advanced(1024, $where_t);
$tag_info = array();
foreach($tags_list_info as $key_t => $val_t){
    $tag_info[] = $tags->get_row($val_t['tag_id']);
}


// ad 广告
$tem=$ad->get_rows(16,'category_id',1);
shuffle($tem);
$ad_right=$tem[0];

// view 加载视图
require VIEW.$url.'.php';

// end of file
